/**
 * Created by CHENED2 on 8/23/2015.
 */
/*
var count1 = 0;
async.whilst(function() {
        return count1 < 3
    },
    function(cb) {
        log('1 count: ', count1);
        count1++;
        setTimeout(cb, 1000);
    },
    function(err) {
        // 3s have passed
        log('1 err: ', err); // -> undefined
    });
*/

var a = undefined;
console.log(!a);
var async = require('async');

var objs = [{name:'A'}, {name:'B'}, {name:'C'}];

function doSomething(obj, cb)
{
    console.log("doing" + obj.name + "!");
    cb(null, obj);
}

async.each(objs, function(obj, callback) {
    doSomething(obj, function(){
        callback();
    });
}, function(err){
    console.log("err is:" + err);
});

async.each(objs, function(obj, callback) {
    doSomething(obj, function(){
        console.log('xxx');
        if(obj.name !='A'){
            callback("It's a err aa.");
        }else{
            callback();
        }

        console.log('sss');
    });
}, function(err){
    console.log("err is:" + err);
});


async.eachSeries(["abc", "def", "ghi"], function(item, a){

    console.log(item);
    setTimeout(function(){
        console.log('wait.....');
        a(null);
    },5000);
   // must call once

}, function(err){

    if(err){
        console.error("error");
    }
});